<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class InitialEvaluationCandidatesController extends AppController {

    var $name = 'InitialEvaluationCandidates';

    function edit($id) {
        //No se envian datos para guardar.
        if (empty($this->data)) {
            $this->InitialEvaluationCandidate->recursive = 0;
            $this->data = $this->InitialEvaluationCandidate->find("first", array("conditions" => array("InitialEvaluationCandidate.id" => $id), 'fields' => array('Candidate.id', 'Candidate.jerarquia', 'InitialEvaluationCandidate.initial_evaluation_id', 'InitialEvaluationCandidate.id', 'InitialEvaluationCandidate.observacion')));

            App::Import('model', 'InitialEvaluation');
            $initialEvaluation = new InitialEvaluation();
            $proyect_id = $initialEvaluation->field('InitialEvaluation.proyect_id', array('InitialEvaluation.id' => $this->data['InitialEvaluationCandidate']['initial_evaluation_id']));
            $this->set('proyect_id', $proyect_id);
        } else {
            if ($this->InitialEvaluationCandidate->saveAll($this->data)) {
                App::Import('model', 'InitialEvaluation');
                $initialEvaluation = new InitialEvaluation();
                $proyect_id = $initialEvaluation->field('InitialEvaluation.proyect_id', array('InitialEvaluation.id' => $this->data['InitialEvaluationCandidate']['initial_evaluation_id']));
                $evaluation_id = $initialEvaluation->field('InitialEvaluation.id', array('InitialEvaluation.id' => $this->data['InitialEvaluationCandidate']['initial_evaluation_id']));
                $this->set('proyect_id', $proyect_id);

                $this->Session->setFlash('Guardado con éxito');
                $this->redirect(array('controller' => 'InitialEvaluations', 'action' => 'families', $evaluation_id, $proyect_id));
            }
        }
    }

}

?>